import { Component } from '@angular/core';
import { ActionSheetController } from 'ionic-angular';
import { ToastController } from 'ionic-angular';
import{LoadingController} from 'ionic-angular';
// import { Storage } from '@ionic/storage';  unused import
import * as moment from 'moment';

@Component({
  selector: 'page-hello-ionic',
  templateUrl: 'hello-ionic.html'
})
export class HelloIonicPage {
  constructor(public actionSheetCtrl: ActionSheetController,public toastCtrl: ToastController,public loadingCtrl:LoadingController) {
        moment("20111031", "YYYYMMDD").fromNow();    
        console.log(moment("20111031", "YYYYMMDD").fromNow());//6年前,引入moment插件成功
  }
/*方法放在constructor外面*/


  presentActionSheet() {
    let actionSheet = this.actionSheetCtrl.create({
      title: 'Modify your album',
      buttons: [
        {
          text: 'Destructive',
          role: 'destructive',
          handler: () => {
            console.log('Destructive clicked');
          }
        },{
          text: 'Archive',
          handler: () => {
            console.log('Archive clicked');
          }
        },{
          text: 'Cancel',
          role: 'cancel',
          handler: () => {
            console.log('Cancel clicked');
          }
        }
      ]
    });
    actionSheet.present();
  }


  /*这些 常用的方法需要封装在serve层里*/
  toast(){
    let toast = this.toastCtrl.create({
      message: 'User was added successfully',
      duration: 3000
    });
    toast.present();
  }

  //loading
    presentLoading() { 
        let loader = this.loadingCtrl.create({ 
            content: "Please wait...", 
            duration: 3000 
        }); 
        loader.present(); 
    } 

}


export class MyClass {
    constructor(){
        moment("20111031", "YYYYMMDD").fromNow();
        console.log(moment("20111031", "YYYYMMDD").fromNow());
    }
}